﻿function PersonCollection() {
    "use strict";

    var that = this;
    that.collection = new Collection();

    that.fetch = function (query) {    
        return personDataService.get(query)
                .done(function (response) {
                    that.collection.set(response.list);
                });
    }

    that.get = function () {    
        return that.collection.get();
    }

    that.add = function (person) {    
        return personDataService.add(person)
                .done(function (response) {
                    person.id = response.value;
                    that.collection.add(person);
                });
    }

    that.edit = function (person) {
        return personDataService.edit(person)
                .done(function (response) {
                    that.collection.edit(person);
                });
    }

    that.remove = function (id) {
        return personDataService.remove(id)
               .done(function (response) {
                   that.collection.remove(id);
               });
    }
}